package com.xiaoyu.lanling.feature.chat.viewholder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.TextView
import com.qmuiteam.qmui.widget.QMUILoadingView
import com.xiaoyu.im.datamodel.MessageDisplayStatus
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.chat.handler.ChatMessageCallItemClickHandler
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageSendCallItem

class ChatMessageSendCallViewHolder : ChatMessageBaseReceiveSendViewHolder<ChatMessageSendCallItem>() {

    private var mFail: ImageButton? = null
    private var mLoading: QMUILoadingView? = null
    private var mVoiceLayout: FrameLayout? = null
    private var mTitle: TextView? = null

    override fun doCreateChildrenView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        val view = layoutInflater.inflate(R.layout.item_chat_send_call, parent, false)
        mFail = view.findViewById(R.id.chat_send_fail)
        mLoading = view.findViewById(R.id.chat_send_loading)
        mVoiceLayout = view.findViewById(R.id.chat_message_voice_layout)
        mTitle = view.findViewById(R.id.chat_message_voice_title)
        return view
    }

    override fun showData(position: Int, itemData: ChatMessageSendCallItem) {
        super.showData(position, itemData)
        if (itemData.messageDisplayStatus == MessageDisplayStatus.SENDING) {
            mLoading?.visibility = View.VISIBLE
            mFail?.visibility = View.GONE
        } else if (itemData.messageDisplayStatus == MessageDisplayStatus.NORMAL_FAIL) {
            mFail?.setImageResource(R.drawable.icon_chat_send_fail)
            mFail?.visibility = View.VISIBLE
            mLoading?.visibility = View.GONE
        } else if (itemData.messageDisplayStatus == MessageDisplayStatus.BLACKED_FAIL) {
            mFail?.setImageResource(R.drawable.icon_chat_check_fail)
            mFail?.visibility = View.VISIBLE
            mLoading?.visibility = View.GONE
        } else {
            mFail?.visibility = View.GONE
            mLoading?.visibility = View.GONE
        }
        mTitle?.text = itemData.title
        ChatMessageCallItemClickHandler.bindSendCallItemClickForViewAndData(mVoiceLayout, itemData)
        ChatMessageCallItemClickHandler.bindSendCallItemLongClickForViewAndData(mVoiceLayout, itemData)
    }
}